﻿///预估成本
function Get_Ygcblock() {

    if (Xrm.Page.getAttribute("new_xscb").getValue() != null) {
        var opportunityid = Xrm.Page.getAttribute("new_xscb").getValue();

        if (opportunityid != null) {
            Xrm.Page.getControl("new_xscb").setDisabled(true);
        }
    }
}


//窗体加载事件
function Ygcblock_Load(){
    debugger;
    Calculatingprofitmethod();
}

//触发预计利润时
Xrm.Page.getAttribute("new_yjlr").addOnChange(function () {
    debugger;
    Calculatingprofitmethod();
});

//触发预计重量时
Xrm.Page.getAttribute("new_zhongliang").addOnChange(function () {
    debugger;
    Calculatingweightmethod();
});

//预计重量触发
function Calculatingweightmethod() {
    //获取预计重量
    var new_zhongliang = Xrm.Page.getAttribute("new_zhongliang").getValue();//预计重量
    if (new_zhongliang != null) {
        var  new_yjlr= Xrm.Page.getAttribute("new_yjlr").getValue();//预计利润
        //预计利润*预计重量
        var profit = new_yjlr * new_zhongliang;
        Xrm.Page.getAttribute("new_profites").setValue(profit);//利润
    }
}

//预计利润触发
function Calculatingprofitmethod(){
    //获取预计利润值
    var new_yjlr = Xrm.Page.getAttribute("new_yjlr").getValue();//预计利润
    if (new_yjlr != null) {
        var new_zhongliang = Xrm.Page.getAttribute("new_zhongliang").getValue();//预计重量
        //预计利润*预计重量
        var profit = new_yjlr * new_zhongliang;
        Xrm.Page.getAttribute("new_profites").setValue(profit);//利润
    }
}